package com.liuzh.deviceinfo.widget;

import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
import android.widget.RemoteViews;
import c.b.a.a.a;
import c.h.a.m0.h;
import java.util.Locale;

public class RamWidget extends AppWidgetProvider {
    public static final /* synthetic */ int a = 0;

    public static void a(Canvas canvas, Paint paint, int i) {
        float strokeWidth = paint.getStrokeWidth();
        float height = ((float) canvas.getHeight()) - strokeWidth;
        canvas.drawArc(strokeWidth, strokeWidth, height, height, 130.0f, ((((float) i) * 1.0f) / 100.0f) * 280.0f, false, paint);
    }

    public static void b(Context context, Bitmap bitmap, int i) {
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(1);
        paint.setColor(-10066330);
        paint.setTextSize((float) h.u(12.0f, context.getResources().getDisplayMetrics()));
        String str = "RAM";
        float measureText = paint.measureText(str);
        int t = h.t(3.0f, context.getResources().getDisplayMetrics());
        canvas.drawText(str, (((float) bitmap.getWidth()) / 2.0f) - (measureText / 2.0f), (float) (bitmap.getHeight() - (t * 2)), paint);
        paint.setStrokeWidth((float) t);
        paint.setStrokeCap(Cap.ROUND);
        paint.setStyle(Style.STROKE);
        paint.setColor(1717986918);
        a(canvas, paint, 100);
        paint.setColor(context.getResources().getColor(2131099708));
        a(canvas, paint, i);
    }

    public void onDisabled(Context context) {
    }

    public void onEnabled(Context context) {
    }

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] iArr) {
        int[] iArr2 = iArr;
        int length = iArr2.length;
        int i = 0;
        while (i < length) {
            int i2 = iArr2[i];
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(), 2131493148);
            Context applicationContext = context.getApplicationContext();
            double d = 0.0d;
            try {
                MemoryInfo memoryInfo = new MemoryInfo();
                ActivityManager activityManager = (ActivityManager) applicationContext.getSystemService("activity");
                double d2;
                double d3;
                Object[] objArr;
                String str;
                String format;
                StringBuilder stringBuilder;
                int i3;
                int t;
                Bitmap createBitmap;
                if (activityManager == null) {
                    d2 = 0.0d;
                    d3 = d2;
                    objArr = new Object[]{Double.valueOf(d / 1024.0d)};
                    str = "%.2fG";
                    format = String.format(Locale.getDefault(), str, objArr);
                    str = String.format(Locale.getDefault(), str, new Object[]{Double.valueOf(d2 / 1024.0d)});
                    stringBuilder = new StringBuilder();
                    i3 = (int) d3;
                    stringBuilder.append(i3);
                    stringBuilder.append("%");
                    remoteViews.setTextViewText(2131296819, stringBuilder.toString());
                    remoteViews.setTextViewText(2131296821, a.e(new StringBuilder(), str, "/", format));
                    t = h.t(80.0f, context.getResources().getDisplayMetrics());
                    createBitmap = Bitmap.createBitmap(t, t, Config.ARGB_8888);
                    b(context, createBitmap, i3);
                    remoteViews.setImageViewBitmap(2131296815, createBitmap);
                    appWidgetManager.updateAppWidget(i2, remoteViews);
                    i++;
                } else {
                    activityManager.getMemoryInfo(memoryInfo);
                    d = (double) ((memoryInfo.totalMem / 1024) / 1024);
                    d2 = d - ((double) ((memoryInfo.availMem / 1024) / 1024));
                    d3 = (100.0d * d2) / d;
                    objArr = new Object[]{Double.valueOf(d / 1024.0d)};
                    str = "%.2fG";
                    format = String.format(Locale.getDefault(), str, objArr);
                    str = String.format(Locale.getDefault(), str, new Object[]{Double.valueOf(d2 / 1024.0d)});
                    stringBuilder = new StringBuilder();
                    i3 = (int) d3;
                    stringBuilder.append(i3);
                    stringBuilder.append("%");
                    remoteViews.setTextViewText(2131296819, stringBuilder.toString());
                    remoteViews.setTextViewText(2131296821, a.e(new StringBuilder(), str, "/", format));
                    t = h.t(80.0f, context.getResources().getDisplayMetrics());
                    createBitmap = Bitmap.createBitmap(t, t, Config.ARGB_8888);
                    b(context, createBitmap, i3);
                    remoteViews.setImageViewBitmap(2131296815, createBitmap);
                    appWidgetManager.updateAppWidget(i2, remoteViews);
                    i++;
                }
            } catch (Exception unused) {
            }
        }
    }
}
